﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace SlideShowGenerator
{
    /// <summary>
    /// Interaction logic for Options.xaml
    /// </summary>
    public partial class Options : Window
    {
        /// <summary>
        /// 
        /// </summary>
        public Options()
        {
            InitializeComponent();
            txtMaxThumbSize.Text = Config.MaxThumbnailSize.ToString();
            txtTempDir.Text = Config.TempDir.FullName;
        }

        private void btOK_Click(object sender, RoutedEventArgs e)
        {
            Config.MaxThumbnailSize = System.Convert.ToInt16(txtMaxThumbSize.Text);
            this.Close();
        }

        private void textBox1_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (! IsNumericString( txtMaxThumbSize.Text))
            {
                txtMaxThumbSize.Text = "";
            }
        }

        private bool IsNumericString(string str)
        {
            int tempInt;

            if (int.TryParse(str, out tempInt))
            {
                return true;
            }
            return false;
        }

        private void btnTempDir_Click(object sender, RoutedEventArgs e)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();
            fbd.SelectedPath = Config.TempDir.FullName;
            DialogResult result = fbd.ShowDialog();
            if (Directory.Exists(fbd.SelectedPath))
            {
                Config.TempDir = new DirectoryInfo(fbd.SelectedPath);
                txtTempDir.Text = Config.TempDir.FullName;
            }
        }

    }
}
